const express = require('express')
const path = require('path')
const url = require('url')
const app = express()

//使用中间件防盗，通过判断请求方的ip地址（位于请求头的referer中）
app.use((req, res, next) => {
	let refer = req.get('referer')
	if (refer) {
		const hostname = new URL(refer).hostname
		console.log(hostname)
		if (hostname === '127.0.0.1') {
			next()
		} else {
			res.status(404).send('404 NOT FOUND')
		}
	} else next()
})
app.use(express.static(path.resolve(__dirname, "./static")))


app.all('/{*path}', (req, res) => {
	res.end('404 NOT FOUND')
})

app.listen(9000, () => {
	console.log('开始监听')
})